tools/libxl: Avoid deliberate NULL pointer dereference
authorAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 25 Nov 2013 11:12:50 +0000 (11:12 +0000)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Mon, 25 Nov 2013 12:29:48 +0000 (12:29 +0000)
Coverity ID: 1055290

Calling LIBXL__LOG_ERRNO(ctx,) with a ctx pointer we have just failed to
allocate is going to end badly.  Opencode a suitable use of xtl_log() instead.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
CC: Ian Campbell <Ian.Campbell@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/libxl/libxl.c

index 9b932628e1701bf736f55602faf097fcfa32785f..6263d1424214bdec4a29cd0afd37d675d6bb259a 100644 (file)
@@ -31,7 +31,9 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version,
 
     ctx = malloc(sizeof(*ctx));
     if (!ctx) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "Failed to allocate context\n");
+        xtl_log(lg, XTL_ERROR, errno, "libxl",
+                "%s:%d:%s: Failed to allocate context\n",
+                __FILE__, __LINE__, __func__);
         rc = ERROR_NOMEM; goto out;
     }